<template>
  <div>
    <zm-dialog
      :title="obj.switchName + '设置'"
      :visible.sync="value"
      append-to-body
      :before-close="dialogClose"
      size="large"
    >
    <p style="color:#f6a944">
        请设置{{ obj.switchName }}规则，设置完成后保存即可生效：
      </p>
      <div class="pd15">
        <div
          v-for="(item, index) in obj.publicDaySet"
          :key="index"
          class="mb10"
        >
          <span v-if="obj.id === '1'">{{
              item.customerType === "1"
                ? "企业客户:"
                : item.customerType === "2"
                ? "个人客户:"
                : item.customerType === "0"
                ? "在公海池内的所有客户:"
                : "地产客户:"
            }}
            <span>{{
                item.daysType === "1"
                  ? "产生过销售单客户，超过"
                  : item.daysType === "2"
                  ? "未产生过销售单客户，超过"
                  : ""
              }}
            </span>
          </span>
          <span v-else>
            {{
              item.customerType === "1"
                ? "企业客户超过"
                : item.customerType === "2"
                ? "个人客户超过"
                : item.customerType === "0"
                ? "在公海池内的所有客户超过"
                : "地产客户超过"
            }}
          </span>
          <zm-input
            v-model="item.days"
            center
            class="w140 mlr5"
            @change="handleChange(item.days)"
            placeholder="请输入"
          >
            <template slot="append">
              天
            </template>
          </zm-input>
          <span>
            {{
                item.daysType === "1"
                  ? "未有新销售单产生会被系统移入公海"
                  : item.daysType === "2"
                  ? "未有销售单产生的客户会被系统放回公海"
                  : item.daysType === "3"
                  ? "未产生跟进记录的客户会被系统放回公海"
                  : "原所属业务员不可领取"
              }}
          </span>
        </div>
      </div>
      <template v-slot:footer class="tr">
        <el-button @click="myCancel" type="">取消</el-button>
        <el-button @click="submit" type="primary">确定</el-button>
      </template>
    </zm-dialog>
  </div>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import { updatePublicDay, updatePublicSwitch } from '@/api/src/customerSet'
export default {
  name: 'SwitchDialog',
  mixins: [dialogMixin],
  props: {

  },
  data () {
    return {

    }
  },
  computed: {

  },
  created () {

  },
  methods: {

    async submit () {
      console.log(this.obj.publicDaySet)
      const reg = /^[1-9]\d*$/
      let flag = this.obj.publicDaySet.some(item => {
        if (!reg.test(item.days)) {
          return this.$message.error('表格中填写的数据应为正整数,请重新填写在提交')
        }
      })
      console.log(flag)
      if (!flag) {
        await updatePublicDay({ customerPublicData: this.obj.publicDaySet })
        await updatePublicSwitch({
          id: this.obj.id,
          status: '1'
        })
        this.$emit('mySubmit')
        this.myCancel()
      } else {
        return
      }
    },
    myCancel () {
      this.$emit('input', false)
    },
    handleChange (value) {
      const reg = /^[1-9]\d*$/
      if (!reg.test(value)) {
        this.$message.error('请输入正整数')
      }
    }

  }
}
</script>
